package com.hd.crdao.wrapper;

import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import com.bumptech.glide.DrawableTypeRequest;
import com.bumptech.glide.Glide;
import com.hd.crdao.R;
import com.hd.crdao.utils.UIUtils;

/**
 * @author Android
 * @date 2018/2/9
 */

public class GlideImageUtils {
    private GlideImageUtils() {
    }

    public static void loadImage(String url, ImageView targetView) {
        Glide.with(UIUtils.getContext())
                .load(url)
                .placeholder(R.drawable.logo_moren_2x)
                .into(targetView);
    }

    public static void loadImage(String url, int resId, ImageView targetView) {
        Glide.with(UIUtils.getContext())
                .load(url)
                .placeholder(resId)
                .into(targetView);
    }

    public static void loadImage(String url, Drawable drawableRes, ImageView targetView) {
        Glide.with(UIUtils.getContext())
                .load(url)
                .placeholder(drawableRes)
                .into(targetView);
    }

    /**
     *
     * @param url 图片地址
     * @param drawableRes 图片的空视图显示
     * @param isChangedCircle 是否只显示圆形
     * @param targetView 目标显示控件
     */
    public static void loadImage(String url, Drawable drawableRes, boolean isChangedCircle, ImageView targetView) {
        DrawableTypeRequest<String> load = Glide.with(UIUtils.getContext()).load(url);
        if (isChangedCircle) {
            load.bitmapTransform(new GlideCircleTransform(UIUtils.getContext()));
        }
        load.placeholder(drawableRes)
                .into(targetView);
    }

    /**
     *
     * @param url 图片地址
     * @param drawableRes 图片的空视图显示
     * @param isChangedCircle 是否只显示圆形
     * @param targetView 目标显示控件
     */
    public static void loadImage(String url, int drawableRes, boolean isChangedCircle, ImageView targetView) {
        DrawableTypeRequest<String> load = Glide.with(UIUtils.getContext()).load(url);
        if (isChangedCircle) {
            load.bitmapTransform(new GlideCircleTransform(UIUtils.getContext()));
        }
        load.placeholder(drawableRes)
                .into(targetView);
    }
}
